package com.nbjtjc.safe.service.edu;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduRequirementItemsSurveyResultsMapper;
import com.nbjtjc.safe.model.edu.EduRequirementItemsSurveyResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EduRequirementItemsSurveyResultsService {

	@Autowired
	  private EduRequirementItemsSurveyResultsMapper eduRequirementItemsSurveyResultsMapper;
		
	  public Result add(EduRequirementItemsSurveyResults eduRequirementItemsSurveyResults){
		        Result result=new Result();
		        if(ObjectUtil.isNull(eduRequirementItemsSurveyResults)
//		        		||ObjectUtil.isNull(eduRequirementItemsSurveyResults.getId())
//		        		||ObjectUtil.isNull(eduRequirementItemsSurveyResults.getReqInvestId())
//		        		||ObjectUtil.isNull(eduRequirementItemsSurveyResults.getUserId())
		        		||ObjectUtil.isNull(eduRequirementItemsSurveyResults.getUserSurveyResultId())
		        		){		            
		        	result.setFalse("关键字段不能为空");
		            return result;
		        }
//主键为空或库中无此主键则为新建，插入数据
		        if(ObjectUtil.isNull(eduRequirementItemsSurveyResults.getId())|| ObjectUtil.isNull(eduRequirementItemsSurveyResultsMapper.selectByPrimaryKey(eduRequirementItemsSurveyResults.getId()))){
		        	int res=eduRequirementItemsSurveyResultsMapper.insertSelective(eduRequirementItemsSurveyResults);
			        if(res==0){
			            result.setFalse("插入需求调查结果项目失败");
			            return result;
			        }
		        }else
		        {
		        	int res=eduRequirementItemsSurveyResultsMapper.updateByPrimaryKeySelective(eduRequirementItemsSurveyResults);
		        	 if(res==0){
		        		 result.setFalse("更新需求调查结果项目失败");
				         return result;

		        	 }
		        }
		        result.setData(eduRequirementItemsSurveyResults);

		        return result;
		    }


	  
	  public Result delete(int eduRequirementItemsSurveyResultsId){
	      Result result=new Result();
	      if(ObjectUtil.isNull(eduRequirementItemsSurveyResultsId)){
	          result.setFalse("删除对象不能为空");
	          return result;
	      }
	      int res = eduRequirementItemsSurveyResultsMapper.deleteByPrimaryKey(eduRequirementItemsSurveyResultsId);
	      if(res==0){
	    	  result.setFalse("删除需求调查结果项目失败");
		      return result;
	
	      }
	      return result;
	  }

	  
	  public Result find(EduRequirementItemsSurveyResults eduRequirementItemsSurveyResults) {
	      Result result = new Result();
	      PageHelper.startPage(eduRequirementItemsSurveyResults.getPageCurrent(), eduRequirementItemsSurveyResults.getPageSize());
	      List<EduRequirementItemsSurveyResults> eduRequirementItemsSurveyResultss = eduRequirementItemsSurveyResultsMapper.select(eduRequirementItemsSurveyResults);
	      result.setData(new PageInfo<>(eduRequirementItemsSurveyResultss));

	      return result;
	  }
}
